package game.core.util
{
	import flash.display.MovieClip;
	
	public class MovieClipDelegate
	{
		private var callback:Function;
		
		private var target:MovieClip;
		
		public function MovieClipDelegate(target:MovieClip,callback:Function = null)
		{
			this.target = target;
			this.callback = callback;
		}
		
		public function execute():void {
			this.target.addFrameScript(this.target.totalFrames - 1,handler);
		}
		
		private function handler():void {
			this.target.addFrameScript(this.target.totalFrames - 1, null);
			this.target.stop();
			DisplayUtil.removeChild(this.target.parent,this.target);
			if(this.callback != null){
				this.callback();
			}
		}
	}
}